package com.matongxue.springboot;

public class BubbleSort {

    public static void main(String[] args) {
        int[] array=new int[]{1,10,8,6,5,2};
        //每次循环 找出一个最大值 冒泡次数
        for (int i = 0; i <array.length-1 ; i++) {
            //怎么比较
            for (int j = 0; j <array.length-1-i ; j++) {
                if(array[j]>array[j+1]){
                    int temp=array[j];
                    array[j]=array[j+1];
                    array[j+1]=temp;
                }
            }

            for (int k = 0; k <array.length ; k++) {
                System.out.print(array[k]+"—— ");
            }
            System.out.println("——排序结果 ");
        }
    }
}
